package com.cy1640.damai.ui.recommand;

import android.content.Context;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.cy1640.damai.R;
import com.cy1640.damai.image.ImageLoader;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by chenyang on 2016/12/16.
 */

public class TypeView1 extends LinearLayout {
    @Bind(R.id.type_title)
    TextView typeTitle;
    @Bind(R.id.type_subtitle)
    TextView typeSubtitle;
    @Bind(R.id.type_container)
    LinearLayout typeContainer;
    private LayoutInflater inflate;

    public TypeView1(Context context) {
        super(context);
        init();
    }

    public TypeView1(Context context, AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    public void init() {
        inflate = LayoutInflater.from(getContext());
        inflate.inflate(R.layout.view_typy1, this, true);
        ButterKnife.bind(this,this);
    }

    public void setData(TypeViewBean data){
        typeTitle.setText(data.getTitle());
        if (TextUtils.isEmpty(data.getSubTitle())) {
            typeSubtitle.setVisibility(GONE);
        } else {
            typeSubtitle.setVisibility(VISIBLE);
            typeSubtitle.setText(data.getSubTitle());
        }

        List<TypeViewDataBean> datalist =data.getList();
        if (datalist.size()>0) {
            for (int i = 0; i <datalist.size() ; i++) {
                ImageView img= (ImageView) inflate.inflate(R.layout.view_type_image,null);
                ImageLoader.getInstance().loadImages(img,datalist.get(i).getPicUrl(),false);
                typeContainer.addView(img);
            }
        }
    }
}
